package com.example.spindrift.Controllers;

import com.example.spindrift.dao.SysSongListMapper;
import com.example.spindrift.models.SysSong;
import com.example.spindrift.models.SysSongList;
import com.example.spindrift.service.SongListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/SongList")
public class SongListController {
    @Autowired
    SongListService songListService;

    @GetMapping("/getAllSongList")
    public List<SysSongList> getAllSongList() {
        return songListService.getAllSongList();
    }

    /**
     * 根据关键字和指定状态获取歌单列表
     * @param keyword 关键字
     * @param states 歌单状态
     * @return
     */
    @GetMapping("/searchSongList")
    public List<SysSongList> searchSongList(@RequestParam String keyword,@RequestParam String states) {
        return songListService.searchSongList(keyword,states);
    }

    /**
     * 根据关键字搜索公共歌单列表
     * @param keyword 关键字
     * @return
     */
    @GetMapping("/searchPublicSongList")
    public List<SysSongList> searchPublicSongList(@RequestParam String keyword){
        return songListService.searchSongList(keyword,"2");
    }

    /**
     * 发布歌单
     * @param songList 更正后的歌单信息
     * @return
     */
    @PutMapping("/issueSongList")
    public Boolean issueSongList(@RequestBody SysSongList songList){
        return songListService.issueSongList(songList);
    }

    /**
     * 审批歌单
     * @param songListId 歌单ID
     * @return
     */
    @GetMapping("/approveSongList")
    public Boolean approveSongList(@RequestParam Integer songListId,@RequestParam Boolean isPass,@RequestParam Integer approveUserId){
        return songListService.approveSongList(songListId,isPass,approveUserId);
    }

    /**
     * 根据歌单ID获取歌单信息
     * @param songListId 歌单ID
     * @return
     */
    @GetMapping("/getSongListById")
    public SysSongList getSongListById(@RequestParam Integer songListId){
        return songListService.getSongListById(songListId);
    }

    /**
     * 获取指定用户所拥有的歌单信息
     * @param userId 用户ID
     * @return
     */
    @GetMapping("/getSongListByUser")
    public List<SysSongList> getSongListByUser(@RequestParam Integer userId) {
        return songListService.getSongListByUser(userId);
    }

    /**
     * 根据歌单ID获取歌单中的歌曲列表信息
     * @param songListId 歌单ID
     * @return
     */
    @GetMapping("/getSongBySongList")
    public List<SysSong> getSongBySongList(@RequestParam Integer songListId) {
        return songListService.getSongBySongList(songListId);
    }

    /**
     * 根据歌曲名称搜索指定歌单信息
     * @param songListId 歌单ID
     * @param keyword 关键字
     * @return
     */
    @GetMapping("/searchSongBySongList")
    public List<SysSong> searchSongBySongList(@RequestParam Integer songListId,String keyword) {
        return songListService.searchSongBySongList(songListId,keyword);
    }

    /**
     * 获取指定状态的歌单信息
     * @param states
     * @return
     */
    @GetMapping("/getSongListByState")
    public List<SysSongList> getSongListByState(@RequestParam String states){
        return songListService.getSongListByState(states);
    }

    /**
     * 获取公共的歌单列表信息
     * @return
     */
    @GetMapping("/getPublicSongList")
    public List<SysSongList> getPublicSongList(){
        return songListService.getSongListByState("2");
    }

    /**
     * 获取待审批的歌单列表
     * @return
     */
    @GetMapping("/getApproveSongList")
    public List<SysSongList> getApproveSongList(){
        return songListService.getSongListByState("1");
    }

    /**
     * 创建一个歌单
     * @param songList 歌单信息
     * @return
     */
    @PostMapping("/insertSongList")
    public Boolean insertSongList(@RequestBody SysSongList songList) {
        return songListService.insertSongList(songList) > 0;
    }

    /**
     * 更新一个歌单信息
     * @param songList 新歌单信息
     * @return
     */
    @PutMapping("/updateSongList")
    public Boolean updateSongList(@RequestBody SysSongList songList) {
        return songListService.updateSongList(songList) > 0;
    }

    /**
     * 根据歌单ID删除一条歌单信息
     * @param songListId 歌单ID
     * @return
     */
    @DeleteMapping("/deleteSongList")
    public Boolean deleteSongList(@RequestParam Integer songListId) {
        return songListService.deleteSongList(songListId) > 0;
    }
}
